import {getBanner, getNewAlbum, getPersonalized} from "@/network/discover/recommend";
import {getRecommendedListOfTheDay} from "@/network/songs/musicrelated";

interface stateInterface {
    banners: null,
    IncompletePersonalized: undefined | {},
    recommendedListOfTheDay: undefined | {}
    newAlbumList: undefined | {}
}

export default {
    namespaced: true,
    status: {
        banners: null,
        IncompletePersonalized: undefined,
        recommendedListOfTheDay: undefined,
        newAlbumList: undefined,
    },
    mutations: {
        GET_BANNER(state: stateInterface, value: any) {
            state.banners = value.banners;
        },
        GET_INCOMPLETE_PERSONALIZED(state: stateInterface, value: any) {
            state.IncompletePersonalized = value.result;
        },
        GET_RECOMMENDED_LIST_OF_THE_DAY(state: stateInterface, value: any) {
            state.recommendedListOfTheDay = value;
        },
        DELETE_RECOMMENDED_LIST_OF_THE_DAY(state: stateInterface) {
            state.recommendedListOfTheDay = undefined;
        },
        GET_NEW_ALBUM_LIST(state: stateInterface, value: any) {
            state.newAlbumList = value;
        },
    },
    actions: {
        async getBanner(context: any, value: number) {
            const {data: res} = await getBanner(value);
            context.commit("GET_BANNER", res);
        },
        async getIncompletePersonalized(context: any, value: { limit: number, cookie?: string }) {
            const {data: res} = await getPersonalized(value.limit, value.cookie);
            context.commit("GET_INCOMPLETE_PERSONALIZED", res);
        },
        async getRecommendedListOfTheDay(context: any, value: string) {
            if (value === "undefined") {
                console.log("没有登陆");
            } else {
                const {data: res} = await getRecommendedListOfTheDay(value);
                //只截取前三个
                const data = res.recommend.slice(0, 3);
                context.commit("GET_RECOMMENDED_LIST_OF_THE_DAY", data);
            }
        },
        async getNewAlbumList(context: any, value: { cookie?: string, limit: number, offset: number }) {
            const {data: res} = await getNewAlbum(value.cookie, value.limit, value.offset);
            context.commit("GET_NEW_ALBUM_LIST", res.albums);
        },

    },
    getters: {},
};
